package cn.iocoder.yudao.module.crossborder.platform.service.platformwebhooklog;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.crossborder.platform.controller.admin.platformwebhooklog.vo.*;
import cn.iocoder.yudao.module.crossborder.platform.dal.dataobject.platformwebhooklog.PlatformWebhookLogDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.crossborder.platform.dal.mysql.platformwebhooklog.PlatformWebhookLogMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.crossborder.platform.enums.ErrorCodeConstants.*;

/**
 * 跨境电商平台Webhook事件日志 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class PlatformWebhookLogServiceImpl implements PlatformWebhookLogService {

    @Resource
    private PlatformWebhookLogMapper platformWebhookLogMapper;

    @Override
    public Long createPlatformWebhookLog(PlatformWebhookLogSaveReqVO createReqVO) {
        // 插入
        PlatformWebhookLogDO platformWebhookLog = BeanUtils.toBean(createReqVO, PlatformWebhookLogDO.class);
        platformWebhookLogMapper.insert(platformWebhookLog);

        // 返回
        return platformWebhookLog.getId();
    }

    @Override
    public void updatePlatformWebhookLog(PlatformWebhookLogSaveReqVO updateReqVO) {
        // 校验存在
        validatePlatformWebhookLogExists(updateReqVO.getId());
        // 更新
        PlatformWebhookLogDO updateObj = BeanUtils.toBean(updateReqVO, PlatformWebhookLogDO.class);
        platformWebhookLogMapper.updateById(updateObj);
    }

    @Override
    public void deletePlatformWebhookLog(Long id) {
        // 校验存在
        validatePlatformWebhookLogExists(id);
        // 删除
        platformWebhookLogMapper.deleteById(id);
    }

    @Override
        public void deletePlatformWebhookLogListByIds(List<Long> ids) {
        // 删除
        platformWebhookLogMapper.deleteByIds(ids);
        }


    private void validatePlatformWebhookLogExists(Long id) {
        if (platformWebhookLogMapper.selectById(id) == null) {
            throw exception(PLATFORM_WEBHOOK_LOG_NOT_EXISTS);
        }
    }

    @Override
    public PlatformWebhookLogDO getPlatformWebhookLog(Long id) {
        return platformWebhookLogMapper.selectById(id);
    }

    @Override
    public PageResult<PlatformWebhookLogDO> getPlatformWebhookLogPage(PlatformWebhookLogPageReqVO pageReqVO) {
        return platformWebhookLogMapper.selectPage(pageReqVO);
    }

}